//
// Particle.cxx
//
// Created by TB on 11/22/11.
// Copyright 2011 BNL. All rights reserved.
//

#include <map>

#ifdef USING_LHAPDF
#include <LHAPDF/LHAPDF.h>
#else
#include "tppmc/Enumerations.h"
#endif

#include "tppmc/Particle.h"

namespace tppmc {

   Parton::Parton(double momX, double momY, double momZ,
          int species, int nucleon, int partonspin, int protonspin)
   : type(species)
   , group(nucleon)
   , spin(partonspin)
   , pspin(protonspin)
   , px(momX)
   , py(momY)
   , pz(momZ)
   , x(0.)
   , cos_spin_depol(0.)
   , phi_spin(0.)
   , mF1(0.)
   , mSivers(0.)
   , mH1(0.)
   , mSiversWeight(0.)
   , mSiversSpinFactor(0.) {
   }

   int Parton::Lhapdf() const {
      
      static std::map<int, int> table;
      
      if(table.empty()) {
         int pdg[14] = {
            1,  2,  3,
            4,  5,  6,
            -1, -2, -3,
            -4, -5, -6,
            21, 22
         };
         int lhapdf[14] = {
            LHAPDF::DOWN,  LHAPDF::UP,     LHAPDF::STRANGE,
            LHAPDF::CHARM, LHAPDF::BOTTOM, LHAPDF::TOP,
            LHAPDF::DBAR,  LHAPDF::UBAR,   LHAPDF::SBAR,
            LHAPDF::CBAR,  LHAPDF::BBAR,   LHAPDF::TBAR,
            LHAPDF::GLUON, LHAPDF::PHOTON
         };
         for(unsigned i(0); i < 14; ++i) {
            table.insert(std::make_pair(pdg[i], lhapdf[i]));
         } // for
      } // if
      
      // Find the entry
      const std::map<int, int>::const_iterator iter =
      table.find(Pdg());
      
      // Didn't find it:
      if(table.end() == iter) return -999;
      
      return iter->second;
   }

   Hadron::Hadron()
   : type(-999)
   , lasthad(-999)
   , favoured(-1)
   , px(0.)
   , py(0.)
   , pz(0.)
   , z(0.)
   , collinsangle(-999.)
   , phigen(-999.)
   , mFrag(0.)
   , mCollins(0.)
   { }

   Hadron Hadron::Test() {
      
      Hadron f;
      f.z = 0.6;
      f.type = 211;
      f.px = 0.6;
      f.py = 0.8;
      f.mParton.type = 2;
      f.mParton.cos_spin_depol = 0.9;
      f.mParton.px = sqrt(2.);
      f.mParton.py = sqrt(2.);
      f.mParton.pz = 10.;
      
      return f;
   }
} // namespace tppmc
